#include "push_service_handler.h"

#include "base/curl_client.h"
#include "base/url_encode.h"
#include "base/hash.h"
#include "base/json_parser.h"
#include "uid_token_map.h"
#include "apns_manager.h"
#include "baiduyun_manager.h"
#include "PushService_constants.h"
#include "im/adapters/UserInfoAdapter.h"

namespace imserver {

void PushServiceHandler::Push(int64_t uid, const std::string& content, int64_t timestamp) {
  std::string token;
  user::UserAdapter::Instance().getUserToken(token, uid);
  LOG_INFO("PushServiceHandler::Push --> uid:" << uid << " content:" << content << " token:" << token);
  //std::string token = "{\"appid\":\"3073438\",\"channelId\":\"4556231272567764840\",\"requestId\":\"145528048\",\"userId\":\"823343208773869594\"}";
  if (token.empty()) {
    return;
  }
  std::map<std::string, std::string> token_data;
  if (!base::JsonParser::instance().parse(token, token_data)) {
    return;
  }
  if (token_data.empty()) {
    return;
  }
  if (token_data.find("channelId") != token_data.end()) {
    BaiduyunManager::instance().pushMsg(token_data["userId"], token_data["channelId"], content, timestamp);

  } /*else if (token.find(g_PushService_constants.APNS_TOKEN_PREFIX) == 0) {
    APNSManager::instance().pushMsg(uid, token, content);

  }*/
}

}


